import cgi

from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.api import mail

class Download(webapp.RequestHandler):
    def get(self):
        email = self.request.get("email")

        message = mail.EmailMessage(sender="L.A.B. Build <build@linuxappliancebox.appspotmail.com>",
                            subject="LAB Build Request")

        message.to = "build@linuxappliancebox.com" 
        message.body = """
base_os=%s
arch=%s
rootfs=%s
install=%s
apptype=%s
        """ % (self.request.get("base_os"), self.request.get("arch"), self.request.get("rootfs"), 
            self.request.get("install"), self.request.get("apptype"))

        message.send()

        message = mail.EmailMessage(sender="L.A.B. Build <build@linuxappliancebox.appspotmail.com>",
                            subject="Thank you for your L.A.B. Build Request")

        message.to = email
        message.body = """
Thank you for submitting your build request. We will send you another mail with the download link.
        """
        message.send()

        self.response.out.write(email)


application = webapp.WSGIApplication(
                                     [('/dl', Download)],
                                     debug=True)

def main():
    run_wsgi_app(application)

if __name__ == "__main__":
    main()
